<!DOCTYPE html> 
<html>
<head>
<style>
	body {
	}
	textarea { 
		width: 233px; 
		height: 18px;
		background-color: #FFFFFF;
	}
	button
	{
		width: 235px;
	}
	
}
</style>
<script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
<script type="text/javascript" src="chrome_ex_oauth.js"></script>
<script>
	var year;
	var title;
	var oauth;

	chrome.tabs.getSelected(null, function (tab) {
		tabToFilmInfo(tab);
	});

	function tabToFilmInfo(tab) {
		var beginYear; 
		var endYear;
		beginYear = tab.title.indexOf("(");
		endYear = tab.title.indexOf(")");		
			
		title = tab.title.substr(0, beginYear - 1);	
		year = tab.title.substr(beginYear + 1, 4);		
	}

	function showFilmInfo() {
		var text = document.getElementById('text'); 
		text.value = title;
		
		setupAuth();
		
		oauth.authorize(onAuthorized());
	}
	
	function callback(resp, xhr) {
		console.log(resp);
	}
	
	function onAuthorized() {
		var url = 'https://openapi.lovefilm.com/catalog/film';
		var request = {
		'method': 'GET',
		'parameters': {'term': title}
		};
		
		console.log(url);
		console.log(request);

		// Send: GET https://openapi.lovefilm.com/catalog/film?term=title
		oauth.sendSignedRequest(url, callback, request);
	}
	
	function logout() {
        oauth.clearTokens();
    }
	
	function setupAuth(){
		oauth = ChromeExOAuth.initBackgroundPage({
			'request_url': 'https://openapi.lovefilm.com/oauth/request_token',
			'authorize_url': 'https://www.lovefilm.com/activate',
			'access_url': 'http://openapi.lovefilm.com/oauth/access_token',
			'consumer_key': 'r3zqy3rer4948d9rnz9kvygs',
			'consumer_secret': '3cEKy8Ph8q',
			'scope': 'https://openapi.lovefilm.com/',
			'app_name': 'IMDb2LOVEFiLM'
		});
	}
	
	function getFilm(){		
	}
	
</script>
</head>
<body>
	<body background="hatched_overlay.gif">
	<textarea id="text"></textarea>
	<button onclick="showFilmInfo();">ShowInfo</button>
	<img src="lovefilm-logo-amazon.jpg" alt="LOVEFiLM" />
</body>
</html>


